<?php

/**
*
* @package MediaLibrary
* @copyright 2009 Andrey Kvasnevskiy-OrdaSoft(akbet@mail.ru);Rob de Cleen(rob@decleen.com)
* Homepage: http://www.joomlawebserver.com
* @version: 1.5.3 Basic $
*
**/

require_once($mosConfig_absolute_path."/components/com_medialibrary/medialibrary.class.php");
require_once($mosConfig_absolute_path."/components/com_medialibrary/medialibrary_game.class.php");
require_once($mosConfig_absolute_path."/components/com_medialibrary/medialibrary_music.class.php");
require_once($mosConfig_absolute_path."/components/com_medialibrary/medialibrary_book.class.php");
require_once($mosConfig_absolute_path."/components/com_medialibrary/medialibrary_video.class.php");
require_once($mosConfig_absolute_path."/administrator/components/com_medialibrary/includes/category.php");


function print_vars($obj) {
    $arr = get_object_vars($obj);
    while (list($prop, $val) = each($arr))
		 if(class_exists($val)) print_vars($val);
		  else echo "\t $prop = $val\n<br />";
}

function print_methods($obj) {
    $arr = get_class_methods(get_class($obj));
    foreach ($arr as $method)   echo "\tfunction $method()\n <br />";
}

if (PHP_VERSION >= 5) {
    // Emulate the old xslt library functions
    function xslt_create() {
        return new XsltProcessor();
    }

    function xslt_process($xsltproc,
                          $xml_arg,
                          $xsl_arg,
                          $xslcontainer = null,
                          $args = null,
                          $params = null) {

        // Create instances of the DomDocument class
        $xml = new DomDocument;
        $xsl = new DomDocument;

        // Load the xml document and the xsl template
        $xml->load($xml_arg);
        $xsl->load($xsl_arg);

        // Load the xsl template
        $xsltproc->importStyleSheet($xsl);

        // Set parameters when defined
        if ($params) {
            foreach ($params as $param => $value) {
                $xsltproc->setParameter("", $param, $value);
            }
        }

        // Start the transformation
        $processed = $xsltproc->transformToXML($xml);

        // Put the result in a file when specified
        if ($xslcontainer) {
            return @file_put_contents($xslcontainer, $processed);
        } else {
            return $processed;
        }

    }

    function xslt_free($xsltproc) {
        unset($xsltproc);
    }
}

class mosMediaLibraryImportExport{
	

	/**
	 * Imports the lines given to this method into the database and writes a
	 * table containing the information of the imported books.
	 * The imported books will be set to [not published] 
	 * Format: #;id;isbn;title;author;language
	 * @param array lines - an array of lines read from the file
	 * @param int catid - the id of the category the books should be added to 
	 */
	function importMediasCSV($lines, $catid){
		global $database;
		$retVal= array();
		$i = 0;
	    	foreach ($lines as $line) {
	    		$tmp = array();

			if(trim($line) == "" ) continue;
	    		$line = explode('|', $line);//edit nik  old -->, -1);
				$book = new mosMediaLibrary($database);
				$book->bookid = trim($line[0]);
				$book->isbn = $line[1];
				$book->title = $line[2];
				$book->authors = $line[3];
				$book->manufacturer = $line[4];
				$book->catid = $catid;
				//$book->date = date("Y-m-d H:i:s");
				$book->date = $line[15];
				$book->language = $line[6];//Language
				$book->comment = $line[16];//Book Description
			            // optimize!!!
			            $tmp[0] = $i;
			            $tmp[1] = trim($line[0]);
			            $tmp[2] = $line[1];
			            $tmp[3] = $line[2];
			            $tmp[4] = $line[3];
			            $tmp[5] = $line[4];
				
				if (!$book->check() || !$book->store()) {
					$tmp[6] =  $book->getError();
				} else {
					$tmp[6] =  "OK";
				}
				$book->checkin();
				$book->updateOrder( "catid='$book->catid'" );
				$retVal[$i] = $tmp;
				$i ++;
			}
			return $retVal;
	}

	function getXMLItemValue($item,$item_name) {
	    $book_items = $item->getElementsByTagname( $item_name );
	    $book_item = $book_items->item(0);
	    if(NULL != $book_item) return $book_item->nodeValue ;
		else return "";	
	}
//****************************************************************************************
//***********************   begin add for import XML format   ****************************
//****************************************************************************************
  function findCategory(& $categories, $new_category ) 
  {
    global $database;
  
    foreach( $categories as $category ){
      if($category->old_id == $new_category->old_id ) return  $category;
    }
    $new_parent_id = null;
    if($new_category->old_parent_id != 0 ){
      foreach( $categories as $category ){
        if($category->old_id == $new_category->old_parent_id ){
          $new_parent_id = $category->id;
          break;
        }
      }
    }
    else $new_parent_id = 0;

    //sanity test
    if( $new_parent_id === null) {
      echo "error in import !"; exit;
    }

    $row = new mosCategory($database);
    $row->section='com_medialibrary';
    $row->parent_id=$new_parent_id ;
    $row->name=$new_category->name ;
    $row->title=$new_category->title ;
    $row->published=$new_category->published ;

    if (!$row->check()) {
      echo "error in import2 !"; exit;
      exit();
    }
    if (!$row->store()) {
      echo "error in import3 !"; exit;
      exit();
    }

    $row->updateOrder("section='com_medialibrary' AND parent_id='$row->parent_id'");

    $new_category->id = $row->id;
    $categories[] = $new_category;

    return  $new_category;
    
  }

  function importMediasXML($files_name_pars,$catid ) 
  {
		global $database;
		$retVal= array();
    $new_categories = array();
		$k = 0;
// loading the xml file as a domdocument 
		$dom = new domDocument('1.0','windows-1251');
    $dom->load($files_name_pars);

	//fetching the categories one by one from the xmal file and adding into the data base
    //get categories
    if($catid === null){
      $cat_list = $dom->getElementsByTagname('category');
      for ($i = 0; $i < $cat_list->length; $i++) {
        $category = $cat_list->item($i);

        $new_category = null;
        $new_category->old_id = mosMediaLibraryImportExport::getXMLItemValue($category,'category_id');
        $new_category->old_parent_id = mosMediaLibraryImportExport::getXMLItemValue($category,'category_parent_id');
        $new_category->name = mosMediaLibraryImportExport::getXMLItemValue($category,'category_name');
        $new_category->title = mosMediaLibraryImportExport::getXMLItemValue($category,'category_title');
        $new_category->published = mosMediaLibraryImportExport::getXMLItemValue($category,'category_published');

        $new_category = mosMediaLibraryImportExport::findCategory($new_categories, $new_category ) ;

      }
    }


		$medias_list = $dom->getElementsByTagname('media');
		$st = $media_id = "";
		$begin = $end = $kol = 0;

		for ($i = 0; $i < $medias_list->length; $i++) {
		    $media_class = new mosMediaLibrary($database);

		    $media = $medias_list->item($i);
 
//		    echo $media->hasChildNodes() . "<br />";

		    //get media_id
		    $media_id = $media_class->media_id = mosMediaLibraryImportExport::getXMLItemValue($media,'media_id');
		    //get media_type
		    $media_type = $media_class->media_type = mosMediaLibraryImportExport::getXMLItemValue($media,'media_type');
		    //get informationFrom
		    $informationFrom = $media_class->informationFrom = 
			    mosMediaLibraryImportExport::getXMLItemValue($media,'informationFrom');
        //get date
        $date = $media_class->date = mosMediaLibraryImportExport::getXMLItemValue($media,'date');
        //get published
        $published = $media_class->published = mosMediaLibraryImportExport::getXMLItemValue($media,'published');


		    //get category
        if($catid === null){
          $categories = $media->getElementsByTagname( 'category_entity' );
          $category = $categories->item(0);
  
          $new_category = null;
          $new_category->old_id = mosMediaLibraryImportExport::getXMLItemValue($category,'category_id');
          $new_category->old_parent_id = mosMediaLibraryImportExport::getXMLItemValue($category,'category_parent_id');
          $new_category->name = mosMediaLibraryImportExport::getXMLItemValue($category,'category_name');
          $new_category->title = mosMediaLibraryImportExport::getXMLItemValue($category,'category_title');
          $new_category->published = mosMediaLibraryImportExport::getXMLItemValue($category,'category_published');
  
          $new_category = mosMediaLibraryImportExport::findCategory($new_categories, $new_category ) ;
  
          //set category
          $media_class->catid = $new_category->id;
        } else {
          $new_category = new mosCategory($database);
          $new_category->Load($catid);
          
          $media_class->catid = $catid;
        }

		  //check media type
		  $media_type_class = null;
      $isbn = null;
		  switch ($media_type)
		  {
		    case 'book':
			    $books = $media->getElementsByTagname( 'book' );
			    $book = $books->item(0);
			    
			    $media_type_class = new mosMedialibrary_book($database);
			  
		      //get book_id
		      $book_id = $media_type_class->book_id = mosMediaLibraryImportExport::getXMLItemValue($book,'book_id');
		      //get isbn
		      $isbn = $media_type_class->isbn = mosMediaLibraryImportExport::getXMLItemValue($book,'isbn');
		      //get title
		      $title = $media_type_class->title = mosMediaLibraryImportExport::getXMLItemValue($book,'title');
		      //get authors
		      $authors = $media_type_class->authors = mosMediaLibraryImportExport::getXMLItemValue($book,'authors');
		      //get manufacturer
		      $manufacturer = $media_type_class->manufacturer = 
				  mosMediaLibraryImportExport::getXMLItemValue($book,'manufacturer');
		      //get release_date
		      $release_date = $media_type_class->release_date = 
				  mosMediaLibraryImportExport::getXMLItemValue($book,'release_date');
		      //get language
		      $language = $media_type_class->language = 
				  mosMediaLibraryImportExport::getXMLItemValue($book,'language');
		      //get rating
		      $rating = $media_type_class->rating = mosMediaLibraryImportExport::getXMLItemValue($book,'rating');
		      //get url
		      $url = $media_type_class->url = mosMediaLibraryImportExport::getXMLItemValue($book,'url');
		      //get price
		      $price = $media_type_class->price = mosMediaLibraryImportExport::getXMLItemValue($book,'price');
		      //get imageURL
		      $imageURL = $media_type_class->imageURL = 
				  mosMediaLibraryImportExport::getXMLItemValue($book,'imageURL');
		      //get edition
		      $edition = $media_type_class->edition = 
				  mosMediaLibraryImportExport::getXMLItemValue($book,'edition');
		      //get ebookURL
		      $ebookURL = $media_type_class->ebookURL = 
				  mosMediaLibraryImportExport::getXMLItemValue($book,'ebookURL');
		      //get comment
		      $comment = $media_type_class->comment = mosMediaLibraryImportExport::getXMLItemValue($book,'comment');
  
			  break;
		    case 'video':
			    $videos = $media->getElementsByTagname( 'video' );
			    $video = $videos->item(0);
			    
			    $media_type_class = new mosMedialibrary_video($database);
			  
		      //get video_id
		      $video_id = $media_type_class->video_id = 
				  mosMediaLibraryImportExport::getXMLItemValue($video,'video_id');
		      //get asin
		      $asin = $media_type_class->asin = mosMediaLibraryImportExport::getXMLItemValue($video,'asin');
		      //get title
		      $title = $media_type_class->title = mosMediaLibraryImportExport::getXMLItemValue($video,'title');
		      //get actors
		      $actors = $media_type_class->actors = mosMediaLibraryImportExport::getXMLItemValue($video,'actors');
		      //get producers
		      $producers = $media_type_class->producers = 
				  mosMediaLibraryImportExport::getXMLItemValue($video,'producers');
		      //get release_date
		      $release_date = $media_type_class->release_date = 
				  mosMediaLibraryImportExport::getXMLItemValue($video,'release_date');
		      //get language
		      $language = $media_type_class->language = 
				  mosMediaLibraryImportExport::getXMLItemValue($video,'language');
		      //get directors
		      $directors = $media_type_class->directors = 
				  mosMediaLibraryImportExport::getXMLItemValue($video,'directors');
		      //get rating
		      $rating = $media_type_class->rating = 
				  mosMediaLibraryImportExport::getXMLItemValue($video,'rating');
		      //get price
		      $price = $media_type_class->price = mosMediaLibraryImportExport::getXMLItemValue($video,'price');
		      //get imageURL
		      $imageURL = $media_type_class->imageURL = 
				  mosMediaLibraryImportExport::getXMLItemValue($video,'imageURL');
		      //get url
		      $url = $media_type_class->url = 
				  mosMediaLibraryImportExport::getXMLItemValue($video,'url');
		      //get studio
		      $studio = $media_type_class->studio = 
				  mosMediaLibraryImportExport::getXMLItemValue($video,'studio');
		      //get evideoURL
		      $evideoURL = $media_type_class->evideoURL = 
				  mosMediaLibraryImportExport::getXMLItemValue($video,'evideoURL');
		      //get comment
		      $comment = $media_type_class->comment = mosMediaLibraryImportExport::getXMLItemValue($video,'comment');
		      //get number_of_discs
		      $number_of_discs = $media_type_class->number_of_discs = 
				  mosMediaLibraryImportExport::getXMLItemValue($video,'number_of_discs');
		      //get run_time
		      $run_time = $media_type_class->run_time = 
				  mosMediaLibraryImportExport::getXMLItemValue($video,'run_time');
  
			  break;
		    case 'music':
			    $musics = $media->getElementsByTagname( 'music' );
			    $music = $musics->item(0);
			    
			    $media_type_class = new mosMedialibrary_music($database);
			  
		      //get music_id
		      $music_id = $media_type_class->music_id = 
				    mosMediaLibraryImportExport::getXMLItemValue($music,'music_id');
		      //get asin
		      $asin = $media_type_class->asin = mosMediaLibraryImportExport::getXMLItemValue($music,'asin');
		      //get title
		      $title = $media_type_class->title = mosMediaLibraryImportExport::getXMLItemValue($music,'title');
		      //get artist
		      $artist = $media_type_class->artist = mosMediaLibraryImportExport::getXMLItemValue($music,'artist');
		      //get label
		      $label = $media_type_class->label = 
				    mosMediaLibraryImportExport::getXMLItemValue($music,'label');
		      //get release_date
		      $release_date = $media_type_class->release_date = 
				    mosMediaLibraryImportExport::getXMLItemValue($music,'release_date');
		      //get language
		      $language = $media_type_class->language = 
				    mosMediaLibraryImportExport::getXMLItemValue($music,'language');
		      //get number_of_discs
		      $number_of_discs = $media_type_class->number_of_discs = 
				    mosMediaLibraryImportExport::getXMLItemValue($music,'number_of_discs');
		      //get rating
		      $rating = $media_type_class->rating = 
				    mosMediaLibraryImportExport::getXMLItemValue($music,'rating');
		      //get price
		      $price = $media_type_class->price = mosMediaLibraryImportExport::getXMLItemValue($music,'price');
		      //get imageURL
		      $imageURL = $media_type_class->imageURL = 
				    mosMediaLibraryImportExport::getXMLItemValue($music,'imageURL');
		      //get url
		      $url = $media_type_class->url = 
				    mosMediaLibraryImportExport::getXMLItemValue($music,'url');
		      //get tracklist
		      $tracklist = $media_type_class->tracklist = 
				    mosMediaLibraryImportExport::getXMLItemValue($music,'tracklist');
		      //get emusicURL
		      $emusicURL = $media_type_class->emusicURL = 
				    mosMediaLibraryImportExport::getXMLItemValue($music,'emusicURL');
		      //get comment
		      $comment = $media_type_class->comment = mosMediaLibraryImportExport::getXMLItemValue($music,'comment');
		      //get binding
		      $binding = $media_type_class->binding = 
				    mosMediaLibraryImportExport::getXMLItemValue($music,'binding');
  
			  break;
		    case 'game':
			    $games = $media->getElementsByTagname( 'game' );
			    $game = $games->item(0);
			    
			    $media_type_class = new mosMedialibrary_game($database);
			  
		      //get game_id
		      $game_id = $media_type_class->game_id = 
				    mosMediaLibraryImportExport::getXMLItemValue($game,'game_id');
		      //get asin
		      $asin = $media_type_class->asin = mosMediaLibraryImportExport::getXMLItemValue($game,'asin');
		      //get title
		      $title = $media_type_class->title = mosMediaLibraryImportExport::getXMLItemValue($game,'title');
		      //get studio
		      $studio = $media_type_class->studio = mosMediaLibraryImportExport::getXMLItemValue($game,'studio');
		      //get binding
		      $binding = $media_type_class->binding = 
				    mosMediaLibraryImportExport::getXMLItemValue($game,'binding');
		      //get release_date
		      $release_date = $media_type_class->release_date = 
				    mosMediaLibraryImportExport::getXMLItemValue($game,'release_date');
		      //get language
		      $language = $media_type_class->language = 
				    mosMediaLibraryImportExport::getXMLItemValue($game,'language');
		      //get rating
		      $rating = $media_type_class->rating = 
				    mosMediaLibraryImportExport::getXMLItemValue($game,'rating');
		      //get price
		      $price = $media_type_class->price = mosMediaLibraryImportExport::getXMLItemValue($game,'price');
		      //get imageURL
		      $imageURL = $media_type_class->imageURL = 
				    mosMediaLibraryImportExport::getXMLItemValue($game,'imageURL');
		      //get url
		      $url = $media_type_class->url = 
				    mosMediaLibraryImportExport::getXMLItemValue($game,'url');
		      //get egameURL
		      $egameURL = $media_type_class->egameURL = 
				    mosMediaLibraryImportExport::getXMLItemValue($game,'egameURL');
		      //get comment
		      $comment = $media_type_class->comment = mosMediaLibraryImportExport::getXMLItemValue($game,'comment');
  
			  break;
		  }

	            //for output rezult in table
	            $tmp[0] = $i;
	            $tmp[1] = ( ($isbn != null )?($isbn):($asin));
	            $tmp[2] = $media_type;
	            $tmp[3] = $new_category->name;
	            $tmp[4] = $title;

        if (!$media_type_class->check() ){
          $tmp[5] =  $media_type_class->_error ;
        } else if( !$media_type_class->store() ) {
          if ($database->getErrorNum()) {
            $tmp[5] .=  $database->stderr();
          }
        } else { $tmp[5] =  "OK"; }

        if( $tmp[5] ==  "OK" ) {
          $media_class->media_id = $media_type_class->id;
          if (!$media_class->check() ){
          $tmp[5] =  $media_class->_error ;
          }else if (!$media_class->store()) {
            if ($database->getErrorNum()) {
              $tmp[5] =  $database->stderr();
            }
		      } else { $tmp[5] =  "OK"; }
          
          if( $tmp[5] != "OK" ){
            $media_type_class->delete( $media_type_class->id );
          }
        }

		    $media_class->checkin();
		    $media_class->updateOrder( "catid='$media_class->catid'" );
		    $retVal[$i] = $tmp;

		    //get Reviews
		    if( $tmp[5] ==  "OK" && mosMediaLibraryImportExport::getXMLItemValue($media,'reviews') != "" ){
			    $review_list = $media->getElementsByTagname('review');
			    for ($j = 0; $j < $review_list->length; $j++) {
  
			      $review = $review_list->item($j);
  
			      //get for review - fk_mediaid == #__medialibrary.id
            $fk_mediaid = $media_class->id;
  
			      //get for review - fk_userid
			      $review_fk_userid = mosMediaLibraryImportExport::getXMLItemValue($review,'fk_userid');
  
			      //check - exist this user or not - if don't exist set he as anonymous
			      $database->setQuery("SELECT id FROM #__users ".
						  "\n WHERE id = ".$review_fk_userid . ";");
			      $review_fk_userid = $database->loadResult();
			      if( count($review_fk_userid) == 0 ) $review_fk_userid = 0;
  
			      //get for review - date
			      $review_date = mosMediaLibraryImportExport::getXMLItemValue($review,'date');
			      //get for review - rating
			      $review_rating = mosMediaLibraryImportExport::getXMLItemValue($review,'rating');
			      //get for review - title
			      $review_title = mosMediaLibraryImportExport::getXMLItemValue($review,'title');
			      //get for review - comment
			      $review_comment = mosMediaLibraryImportExport::getXMLItemValue($review,'comment');
  
			      //insert data in table jos_medialibrary_review
			      $database->setQuery("INSERT INTO #__medialibrary_review".
				      " (fk_mediaid, fk_userid, date, rating, title, comment)".
				      " VALUES ".
				      " (".$fk_mediaid.", ".$review_fk_userid.", '".$review_date.
              "',".$review_rating.",'".$review_title."', '".$review_comment."');");
			          $database->query();
  
	  		 } //end for(...) - REVIEW

  		 } 

		}//end for(...) - Media

		return $retVal;
	}
//*******************************************************************************
//***********************   end add for import XML format   *********************
//*******************************************************************************

	function exportMediasXML($medias){
		global $mosConfig_live_site, $mosConfig_absolute_path, $medialibrary_configuration,$database;

		$xmlDoc =& new DOMIT_Document();	
		$xmlDoc->appendChild($xmlDoc->createProcessingInstruction('xml', "version=\"1.0\" encoding=\"iso-8859-2\"")); 

    $media_data_dom =  & $xmlDoc->createElement("media_data");

      //create and append list element
      $categories_dom =  & $xmlDoc->createElement("categories");

      //$xmlDoc->appendChild($categories_dom);

      $database->setQuery("SELECT name, title,section, id, parent_id, published FROM #__categories ".
                "WHERE section='com_medialibrary' order by parent_id ; " );
      $categories = $database->loadObjectList();   

      foreach($categories as $category){
      //add category
        $category_dom = & $xmlDoc->createElement("category");
    
        $category_id = & $xmlDoc->createElement("category_id");
        $category_id->appendChild($xmlDoc->createTextNode($category->id));
        $category_dom->appendChild( $category_id );

        $category_parent_id = & $xmlDoc->createElement("category_parent_id");
        $category_parent_id->appendChild($xmlDoc->createTextNode($category->parent_id));
        $category_dom->appendChild( $category_parent_id );
    
        $category_name = & $xmlDoc->createElement("category_name");
        $category_name->appendChild($xmlDoc->createCDATASection($category->name));
        $category_dom->appendChild( $category_name );
    
        $category_title = & $xmlDoc->createElement("category_title");
        $category_title->appendChild($xmlDoc->createCDATASection($category->title));
        $category_dom->appendChild( $category_title );
    
        $category_section = & $xmlDoc->createElement("category_section");
        $category_section->appendChild($xmlDoc->createTextNode($category->section));
        $category_dom->appendChild( $category_section );
    
        $category_published = & $xmlDoc->createElement("category_published");
        $category_published->appendChild($xmlDoc->createTextNode($category->published));
        $category_dom->appendChild( $category_published );
  
   
        $categories_dom->appendChild( $category_dom);


      //create and append list element
      $media_data_dom->appendChild($categories_dom);
    }

    //create and append list element
    $medias_dom = & $xmlDoc->createElement("medias");

    foreach ($medias as $media) {
      $medias_dom->appendChild( $media->toXML( $xmlDoc ) );
    }
    $media_data_dom->appendChild($medias_dom);

    $xmlDoc->appendChild($media_data_dom);

    return $xmlDoc->toNormalizedString ();

	}
	
	function storeExportFile($data, $type){
		global $mosConfig_live_site, $mosConfig_absolute_path, $medialibrary_configuration;
		$fileName = "medialibrary_" . date("Ymd_His");
		$fileBase = "/administrator/components/com_medialibrary/exports/";
		


//echo 'PRINT : '.$mosConfig_absolute_path;exit;

		//write the xml file
		$fp = fopen($mosConfig_absolute_path . $fileBase . $fileName . ".xml" , "w", 0); #open for writing
  		
                fwrite($fp, $data); #write all of $data to our opened file
  		fclose($fp); #close the file
  		
  		
  		$InformationArray = array();
  		$InformationArray['xml_file'] = $fileName . '.xml';
  		$InformationArray['log_file'] = $fileName . '.log';
  		$InformationArray['fileBase'] = "file://" . getcwd (). "/components/com_medialibrary/exports/";
  		$InformationArray['urlBase'] = $mosConfig_live_site . $fileBase;
  		$InformationArray['out_file'] = $InformationArray['xml_file'];
  		$InformationArray['error'] = null;
  		
  		switch($type){
  			case 'csv':
	  			$InformationArray['xslt_file'] = 'csv.xsl';
	  			$InformationArray['out_file'] = $fileName . '.csv';
	  			mosMediaLibraryImportExport :: transformPHP4($InformationArray);
  			break;
  			
  			default:
  			break;
  		}

		return $InformationArray;
	}

	
	function transformPHP4(&$InformationArray){
			// create the XSLT processor^M
			$xh = xslt_create() or die("Could not create XSLT processor");
			
			// Process the document
			$result = xslt_process($xh, $InformationArray['fileBase'].$InformationArray['xml_file'], $InformationArray['fileBase'].$InformationArray['xslt_file'], $InformationArray['fileBase'].$InformationArray['out_file']);
			
			if (!$result)
      {

			    // Something croaked. Show the error
$InformationArray['error'] = "Cannot process XSLT document: " . xslt_errno($xh) . " " . xslt_error($xh);
			} 
			
			// Destroy the XSLT processor
			xslt_free($xh);

	}
//////////  MY  ///////////////////////////////////////////////
function remove_info()
{
	global $database;
  $database->setQuery('truncate #__medialibrary');
  $database->query(); 
  if ($database->getErrorNum()) {
    echo $database->stderr();
    return $database->stderr();
  }
  $database->setQuery('truncate #__medialibrary_game');
  $database->query(); 
  if ($database->getErrorNum()) {
    echo $database->stderr();
    return $database->stderr();
  }
  $database->setQuery('truncate #__medialibrary_music');
  $database->query(); 
  if ($database->getErrorNum()) {
    echo $database->stderr();
    return $database->stderr();
  }
  $database->setQuery('truncate #__medialibrary_video');
  $database->query(); 
  if ($database->getErrorNum()) {
    echo $database->stderr();
    return $database->stderr();
  }
  $database->setQuery('truncate #__medialibrary_book');
  $database->query(); 
  if ($database->getErrorNum()) {
    echo $database->stderr();
    return $database->stderr();
  }
	$database->setQuery("delete from #__categories where section='com_medialibrary'");
	$database->query();	
	if ($database->getErrorNum()) {
		echo $database->stderr();
		return $database->stderr();
	}
	$database->setQuery('truncate #__medialibrary_review');
	$database->query();	
	if ($database->getErrorNum()) {
		echo $database->stderr();
		return $database->stderr();
	}
	return "";

}
// function entire_import($file)
// {
// 	global $mosConfig_absolute_path;
// 	$ret = mosMediaLibraryImportExport::remove_info();
// 	if( $ret != "" ) return;
// 	$fp = fopen($file,"r");
// 	$whole = fread($fp,filesize($file));
// 	$pc = array();
// 	$pc = explode('###',$whole);
// 	$urr = mosMediaLibraryImportExport::import_cat(trim($pc[1]),trim($pc[3]));	
// 	if( !is_array($urr) ) return;
// 	$ret = mosMediaLibraryImportExport::import_book(trim($pc[0]),trim($pc[2]),$urr);
// 	//$pc[4]=review,$pc[5]=isbn
// 	$ret = mosMediaLibraryImportExport::import_review(trim($pc[4]),trim($pc[5]));
// 	if( $ret == "" ) echo "<h2 style='color:#0f0;'>OK</h2>";
// }

}
?>
